package saolei;

import java.io.FileNotFoundException;
import java.io.IOException;

import javax.swing.JOptionPane;

public class Main {
    public static void main(String[] args) throws FileNotFoundException, IOException, InterruptedException {
        /* 读取记录 */
        Records records = new Records();
        try {
            records.readRecords("././Records/records.txt");
        } catch (Exception e) {
            // 这个很重要，不能throw，空的时候会报错
        }
        /* 创建扫雷游戏 */
        MineField mf = new MineField(5, 9, 10);
        mf.init();
        mf.printmines();
        GameGUI gg = new GameGUI();
        gg.CreateGame(5, 9, 10, mf);
        /* 插入记录 */
        while (true) {
            if (gg.getIs_Victory() == -1)
                Thread.sleep(100);
            else 
                break;
        }
        if (gg.getIs_Victory() == 1) {
            JOptionPane.showMessageDialog(null, "恭喜你，你赢了");
            int time = (int) gg.getTime();
            Record r = new Record("3", "test3", time);
            records.insertRecord(r);
            records.writeRecords("././Records/records.txt");
        }else
        JOptionPane.showMessageDialog(null, "很遗憾，你输了");
        /* 查找对应id的记录 */
        Records idRecords = records.getRecords("3");
        for (Record i : idRecords)
            System.out.println(i.toString());
        return;
    }
}
